package com.ljsw.fragment;

import java.util.ArrayList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.TextView;
import com.ljsw.activity.R;
import com.ljsw.application.App;
import com.ljsw.dialog.FingerDialog;
import com.ljsw.dialog.RwlqDialog;
import com.ljsw.dialog.YuangongDialog;
import com.ljsw.entity.MessageClass;

/**
 * 任务信息 领取任务fragment
 * 作者: 石锚  不用了
 * 版本: 1.0
 * 日期: 2015-10-16
 */
public class RwlqFragment extends BaseFragment implements OnClickListener{
	Resources r;//测试的时候用下
	private FingerDialog fingerDialog;//指纹验证Dialog
	private RwlqDialog  rwlqdialog;//任务信息Dialog
	private YuangongDialog ygDialog; //银行人员Dialog
	private MessageClass msg ;//任务信息
	private View view;//视图
	private ArrayList<String> list = new ArrayList<String>();//要扫描的集合数据
	//可以点击
	private TextView start_rwlq,//领取任务
				     fw_bankry_rwxx1,//银行人员一
		             fw_bankry_rwxx2;//银行人员二
	//不可点击 		  企业名称                    封包方式           服务内容           联系人1                            电话1                服务内容 联系人2     电话2
	private TextView qiyeName_rwxx,fbfs_rwxx,fwnr_rwxx,lianxiren_rwxx1,tel_rwxx1,lianxiren_rwxx2,tel_rwxx2,
					//路线信息                      押运车牌号         上门服务地点           服务日期                  服务时间                周转箱编号   押运人员
					luxianxinxi_rwxx,carId_rwxx,sm_area_rwxx,fw_date_rwxx,fw_time_rwxx,fw_zzxId,fw_yyry;
	

	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		view = inflater.inflate(R.layout.fragmnet_rwlq, container,false);
		r = getActivity().getResources();//模拟用(上线是会删除)
		rwlqdialog = getDialog();//得到要加载的Dialog
		fingerDialog = getFingerDialog();
		ygDialog = getYgDialog();
		Bundle bundle = getArguments();
		msg = (MessageClass) bundle.getSerializable("msg");
		initView();
		load();
		return view;
	}
	/**
	 * 初始化控件
	 */
	public void initView(){
        start_rwlq = (TextView) view.findViewById(R.id.start_rwlq);//领取任务
		fw_bankry_rwxx1 = (TextView) view.findViewById(R.id.fw_bankry_rwxx1);//银行人员一
        fw_bankry_rwxx2 = (TextView) view.findViewById(R.id.fw_bankry_rwxx2);//银行人员二
        start_rwlq.setOnClickListener(this);
        fw_bankry_rwxx1.setOnClickListener(this);
        fw_bankry_rwxx2.setOnClickListener(this);
        qiyeName_rwxx = (TextView) view.findViewById(R.id.qiyeName_rwxx);
        fbfs_rwxx = (TextView) view.findViewById(R.id.fbfs_rwxx);
        fwnr_rwxx= (TextView) view.findViewById(R.id.fwnr_rwxx);
        lianxiren_rwxx1= (TextView) view.findViewById(R.id.lianxiren_rwxx1);
        tel_rwxx1= (TextView) view.findViewById(R.id.tel_rwxx1);
        lianxiren_rwxx2= (TextView) view.findViewById(R.id.lianxiren_rwxx2);
        tel_rwxx2= (TextView) view.findViewById(R.id.tel_rwxx2);
		luxianxinxi_rwxx= (TextView) view.findViewById(R.id.luxianxinxi_rwxx);
		carId_rwxx= (TextView) view.findViewById(R.id.carId_rwxx);
		sm_area_rwxx= (TextView) view.findViewById(R.id.sm_area_rwxx);
		fw_date_rwxx= (TextView) view.findViewById(R.id.fw_date_rwxx);
		fw_time_rwxx= (TextView) view.findViewById(R.id.fw_time_rwxx);
		fw_zzxId= (TextView) view.findViewById(R.id.fw_zzxId);
		fw_yyry= (TextView) view.findViewById(R.id.fw_yyry);
		/**
		 * 给相应的控件赋值
		 */
		qiyeName_rwxx.setText(msg.getArea());
		fbfs_rwxx.setText(msg.getType());
		fwnr_rwxx.setText(msg.getService());
		luxianxinxi_rwxx.setText(msg.getLine());
		sm_area_rwxx.setText(msg.getStree());
		fw_date_rwxx.setText(msg.getDate());
		fw_time_rwxx.setText(msg.getTime());
	}
	/**
	 * 扫描通知
	 */
	private Handler handler = new Handler(){
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1://显示扫描的结果
	
				break;

			default:
				break;
			}
		};
	};
	@Override
	public void onStart() {
		super.onStart();
//		GetFingerValue.handler = new Handler() {
//			@Override
//			public void handleMessage(Message msg) {
//				super.handleMessage(msg);
//				Bundle bundle;
//				System.out.println("aaaaaaaaa");
//				if (msg.what == 1) {
//					bundle = msg.getData();
//					System.out.println(bundle.getString("finger"));
//					if (bundle != null && bundle.getString("finger").equals("正在获取指纹特征值！")) {
//						System.out.println("指纹验证呢?.....");
//					} else if (bundle != null && bundle.getString("finger").equals("获取指纹特征值成功！")) {
//						
//						fingerDialog.setTitle("押运员正在进行指纹认证...");
//					}
//				}
//			}
//		};
	}
	
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.start_rwlq://领取任务点击
			new RwlqDialog(getActivity()).builder().setPositiveButton("确认", new OnClickListener() {				
				public void onClick(View arg0) {		
					// 弹出新的Dialog
					rwlqdialog.show();
					rwlqdialog.creatAdapter();
					rwlqdialog.setAdapter();
				}
			}).setNegativeButton("取消", new OnClickListener() {			
				public void onClick(View arg0) {		
				}
			}).show();
			break;
		case R.id.fw_bankry_rwxx1://银行人员一点击
			ygDialog.show();
			ygDialog.setDanweiName("天津农商银行北辰支行");
			ygDialog.setGonghao("1000001");
			ygDialog.setYgname(fw_bankry_rwxx1.getText().toString());
			ygDialog.setShenfenzheng("30432347290732432");
			Bitmap bmp=BitmapFactory.decodeResource(r, R.drawable.u123);
			ygDialog.setHeadBitmap(bmp);
			break;
		case R.id.fw_bankry_rwxx2://银行人员二点击
			ygDialog.show();
			ygDialog.setDanweiName("天津农商银行武清支行");
			ygDialog.setGonghao("1000002");
			ygDialog.setYgname(fw_bankry_rwxx2.getText().toString());
			ygDialog.setShenfenzheng("304323490754654641");
			Bitmap bmp2=BitmapFactory.decodeResource(r, R.drawable.u138);
			ygDialog.setHeadBitmap(bmp2);
			break;
		}
	}
	/**
	 * 员工Dialog
	 * @return
	 */
	public YuangongDialog getYgDialog(){
		ygDialog =  new YuangongDialog(getActivity()).builder().setQueDing("确定", new OnClickListener() {
			public void onClick(View arg0) {
				
			}
		});
		return ygDialog;
	}
	/**
	 * 指纹验证Dialog
	 * @return
	 */
	public  FingerDialog getFingerDialog(){
		fingerDialog = new FingerDialog(getActivity()).builder().setQueDing(new OnClickListener() {
			public void onClick(View arg0) {
				
			}
		});	
		return fingerDialog;
	}
	/**
	 * 在当前页面方便执行其他的操作,暂时不提取出来
	 * @return
	 */
	public  RwlqDialog getDialog(){
		rwlqdialog = new RwlqDialog(getActivity()).builder2().setPositiveButton2("确定", new OnClickListener() {
			public void onClick(View arg0) {
	//			getRfid().close_a20();
//				getRfid().addNotifly(new GetFingerValue()); // 添加通知 
//			      new Thread(new Runnable() {				
//						public void run() {
//							getRfid().fingerOpen();			
//						}
//			     }).start();
				// 弹出新的Dialog  进行指纹验证
				fingerDialog.show();
		//		fingerDialog.setNameLeft(App.getApp().getName());
				fingerDialog.setNameRight("小王");
			}
		}).setNegativeButton2("取消", new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
			}
		});	
		return rwlqdialog;
	}
	
	/**
	 * 初始化数据扫描的
	 */
	public void load(){
		list.add("HS0000001");
		list.add("HS0000002");
		list.add("HS0000003");
		list.add("HS0000004");
		list.add("HS0000005");
	}
	
	@Override
	public void onStop() {
		super.onStop();
		
	}
}
